package command

import (
	"time"

	"ssnotify/common/dto"
	"ssnotify/common/utils"
	"ssnotify/internal/notify/models"
)

type NotifyConfigAddReq struct {
	Name           string `json:"name" comment:"通知名称" vd:"len($)>0"`
	Source         string `json:"source" comment:"来源：1：告警  2：用户操作 3：系统任务" vd:"len($)>0"`
	Status         string `json:"status" comment:"状态：生效或不生效"`
	DeptId         string `json:"deptId" comment:"分组id"`
	TemplateId     string `json:"templateId" comment:"模板id" vd:"len($)>0"`
	Type           string `json:"type"`
	SendTarget     string `json:"sendTarget" comment:"通知方式、短信、应用内等" vd:"len($)>0"`
	SendTargetType string `json:"sendTargetType" comment:"通知方式、短信、应用内等" vd:"len($)>0"`
	dto.UserInfo
}

func (d *NotifyConfigAddReq) Generate(model *models.NotifyConfig) {
	model.Id = utils.SimpleUUID()
	model.Name = d.Name
	model.Source = d.Source
	model.Status = d.Status
	model.DeptId = d.DeptId
	model.TemplateId = d.TemplateId
	model.SendTarget = d.SendTarget
	model.SendTargetType = d.SendTargetType
	model.CreatorId = d.UserId
	model.Creator = d.UserName
	model.AgencyId = d.AgencyId
	now := dto.LocalTime(time.Now())
	model.CreateTime = &now
	model.Type = d.Type
}

type NotifyConfigModReq struct {
	Id             string `json:"id" comment:"通知配置id" vd:"len($)>0"`
	Name           string `json:"name" comment:"通知名称"`
	Source         string `json:"source" comment:"来源：1：告警  2：用户操作 3：系统任务"`
	Status         string `json:"status" comment:"状态：生效或不生效"`
	DeptId         string `json:"deptId" comment:"分组id"`
	TemplateId     string `json:"templateId" comment:"模板id"`
	Type           string `json:"type" comment:"通知类型"`
	SendTarget     string `json:"sendTarget" comment:"通知方式、短信、应用内等"`
	SendTargetType string `json:"sendTargetType" comment:"通知方式、短信、应用内等"`
	dto.UserInfo
}

func (d *NotifyConfigModReq) Generate(model *models.NotifyConfig) {
	if len(d.Name) > 0 {
		model.Name = d.Name
	}
	if len(d.Source) > 0 {
		model.Source = d.Source
	}
	if len(d.Status) > 0 {
		model.Status = d.Status
	}
	if len(d.DeptId) > 0 {
		model.DeptId = d.DeptId
	}
	if len(d.TemplateId) > 0 {
		model.TemplateId = d.TemplateId
	}
	if len(d.SendTarget) > 0 {
		model.SendTarget = d.SendTarget
	}
	if len(d.SendTargetType) > 0 {
		model.SendTargetType = d.SendTargetType
	}
	model.CreatorId = d.UserId
	model.Creator = d.UserName
	now := dto.LocalTime(time.Now())
	model.UpdateTime = &now
	model.AgencyId = d.AgencyId
	if len(d.Type) > 0 {
		model.Type = d.Type
	}
}

type NotifyConfigDelReq struct {
	Ids []string `form:"ids" json:"ids"`
}

type NotifyConfigInvokeReq struct {
	Id   string                 `json:"id" comment:"通知配置id" vd:"len($)>0"`
	Data map[string]interface{} `json:"data" comment:"通知数据内容" vd:"len($)>0"`
	dto.UserInfo
}
